package com.example.administrator.szb.fragments.base;

import android.app.Activity;
import android.content.Context;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.View;

import com.example.administrator.szb.activity.base.BasePresenter;
import com.example.administrator.szb.util.IosDiaolog;

/**
 * Created by stone on 2017/12/27.
 */

public abstract class MVPBaseFragment <V,T extends BasePresenter> extends Fragment {
    //上下文
    protected Activity activity;
    protected Context context;
    private static final String TAG = "MVPBaseFragment";
    protected T mPresenter;//presenter对象
    protected IosDiaolog iosDiaolog;

    @Override
    public void onViewCreated(View view, Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);
        activity = getActivity();
        context = getContext();
        initView(view);
        iosDiaolog = new IosDiaolog(getActivity());
        mPresenter = createPresenter();//创建presenter
        if (mPresenter!=null){
            mPresenter.setActivity(getActivity());
            mPresenter.attachView((V)this);//view与presenter建立关联
        }
        initEvent();
        initData();
    }
    protected abstract  T createPresenter();
    protected abstract void initView(View view);
    protected abstract void initEvent();
    protected abstract void initData();

    @Override
    public void onDestroy() {
        super.onDestroy();
        if (mPresenter!=null){
            mPresenter.detachView();
        }
        iosDiaolog.hide();
    }
}
